import {
  DesktopOutlined,
  FileOutlined,
  PieChartOutlined,
  TeamOutlined,
  UserOutlined,
} from '@ant-design/icons';
import { Breadcrumb, Layout, Menu } from 'antd';
import React, { useState } from 'react';
import {NavLink,Outlet,useLocation} from "react-router-dom"
const { Header, Content, Footer, Sider } = Layout;


function getItem(label, key, icon, children) {
  return {
    key,
    icon,
    children,
    label,
  };
}

const items = [
  getItem(<NavLink to="/home/dh1">导航1</NavLink>, '1', <PieChartOutlined />),
  getItem('User', 'sub1', <UserOutlined />, [
    getItem(<NavLink to="/home/dh2">导航2</NavLink>, '3'),
    getItem(<NavLink to="/home/dh3">导航3</NavLink>, '4')
  ])
];
// 面包屑的映射关系
const breadcrumbNameMap = {
  '/home': 'home',
  '/home/dh1': '导航1',
  '/home/dh2': '导航2',
  '/home/dh3': '导航3',
 
};
const App = () => {
  const [collapsed, setCollapsed] = useState(false);
  const location = useLocation();
  console.log(location.pathname)
  console.log(location.pathname.split("/"),1111);
  const pathSnippets = location.pathname.split('/').filter((i) => i);
  console.log(pathSnippets,2222);
  const extraBreadcrumbItems = pathSnippets.map((_, index) => {
    const url = `/${pathSnippets.slice(0, index + 1).join('/')}`;
    return (
      <Breadcrumb.Item key={url}>
        <NavLink to={url}>{breadcrumbNameMap[url]}</NavLink>
      </Breadcrumb.Item>
    );
  });
  return (
    <Layout
      style={{
        minHeight: '100vh',
      }}
    >
      <Sider collapsible collapsed={collapsed} onCollapse={(value) => setCollapsed(value)}>
        <div className="logo" />
        <Menu theme="dark" defaultSelectedKeys={['1']} mode="inline" items={items} />
      </Sider>
      <Layout className="site-layout">
        <Header
          className="site-layout-background"
          style={{
            padding: 0,
          }}
        />
        <Content
          style={{
            margin: '0 16px',
          }}
        >
          <Breadcrumb
            style={{
              margin: '16px 0',
            }}
          >
           {
             extraBreadcrumbItems
           }
          </Breadcrumb>
          <div
            className="site-layout-background"
            style={{
              padding: 24,
              minHeight: 360,
            }}
          >
            <Outlet></Outlet>
          </div>
        </Content>
        <Footer
          style={{
            textAlign: 'center',
          }}
        >
          Ant Design ©2018 Created by Ant UED
        </Footer>
      </Layout>
    </Layout>
  );
};

export default App;
